# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     test
   Description :
   Author :       Flyoung
   date：          2023/3/17
-------------------------------------------------
   Change Activity:
                   2023/3/17:
-------------------------------------------------
"""
from compiler.state_machine.lib import epsilon
from compiler.state_machine.utils import construct_directed_graph
from compiler.state_machine.visual_utils import show_dict, state_transition_table_visual

"""

test case template :

def test_case_number():
    '''
    :return: NFA 描述字典，初始状态，接收状态，字母表
    '''
    
"""


def test_case_1():
    alphabet = ['a', 'b']
    input_d = {
        '0': {
            epsilon: ['1', '7']
        },
        '1': {
            epsilon: ['2', '4']
        },
        '2': {
            'a': ['3']
        },
        '3': {
            epsilon: ['6']
        },
        '4': {
            'b': ['5']
        },
        '5': {
            epsilon: ['6']
        },
        '6': {
            epsilon: ['1', '7']
        },
        '7': {
            'a': ['8']
        },
        '8': {
            'b': ['9']
        },
        '9': {

        }
    }
    states = construct_directed_graph(input_d, len(input_d) - 1)
    start = states[0]
    ends = [states[-1]]
    return input_d, start, ends, alphabet


def test_case_2():
    alphabet = ['a', 'b']
    input_d = {
        '0': {
            epsilon: ['1']
        },
        '1': {
            epsilon: ['2'],
            'a': ['3']
        },
        '2': {
            'b': ['2'],
            epsilon: ['4']
        },
        '3': {
            'b': ['3'],
            epsilon: ['4']
        },
        '4': {
            epsilon: ['1', '5']
        },
        '5': {

        }
    }
    states = construct_directed_graph(input_d, len(input_d) - 1)
    start = states[0]
    ends = [states[-1]]
    return input_d, start, ends, alphabet


def test_case_3():
    input_d = {
        '0': {
            '0': ['1'],
            '1': ['2']
        },
        '1': {

        },
        '2': {
            epsilon: ['3']
        },
        '3': {
            '0': ['4'],
            '1': ['4']
        },
        '4': {
            epsilon: ['5']
        },
        '5': {

        }
    }
    alphabet = ['0', '1']
    states = construct_directed_graph(input_d, len(input_d) - 1)
    start = states[0]
    ends = [states[0], states[4], states[5]]
    return input_d, start, ends, alphabet


def test_case_4():
    input_d = {
        '0': {
            'a': ['1']
        },
        '1': {
            epsilon: ['2', '3']
        },
        '2': {
            'b': ['1'],
            'c': ['3']
        },
        '3': {
            'a': ['2'],
            'd': ['1']
        }
    }
    alphabet = ['a', 'b', 'c', 'd']
    states = construct_directed_graph(input_d, len(input_d) - 1)
    start = states[0]
    ends = [states[1], states[2]]
    return input_d, start, ends, alphabet


def test_case_check(
        input_d, start, ends,
        dfa, dfa_start, dfa_ends, dfa_desc,
        is_simplified, simplified_dfa, simplify_start, simplify_ends, simplified_dfa_desc
):
    """
    展示测试结果
    :param input_d: NFA
    :param start: NFA 的起始状态
    :param ends: NFA 的接收状态
    :param dfa: DFA 的起始状态
    :param dfa_start: DFA 的起始状态
    :param dfa_ends: DFA 的接收状态
    :param is_simplified: DFA 是否可以简化
    :param simplified_dfa: 简化后的 DFA
    :param simplify_start: 简化后的 DFA 的起始状态
    :param simplify_ends: 简化后的 DFA 的接收状态
    :return:
    """
    show_dict(dfa_desc, title='DFA Desc')
    state_transition_table_visual(input_d, start_state=start, end_states=ends, title='NFA')
    state_transition_table_visual(dfa, dfa_start, dfa_ends, title='DFA')
    if is_simplified:
        show_dict(simplified_dfa, title='Simplified DFA')
        show_dict(simplified_dfa_desc, title='Simplified DFA Desc')
        state_transition_table_visual(simplified_dfa, simplify_start, simplify_ends, title='Simplified DFA')
    else:
        print('This DFA cannot be simplified')
